using System;
using System.Collections.Generic;
using System.Xml;

namespace Studio.Game.GameBox
{
    /// <summary>
    /// Script Expert, Parse Script
    /// </summary>
    public class AgentScript
    {
        protected IList<AgentScriptSentence> _Sentences;
        /// <summary>
        /// Sentence Collection
        /// </summary>
        public IList<AgentScriptSentence> Sentences
        {
            get { return _Sentences; }
        }

        protected int _Index = 0;
        /// <summary>
        /// Current Sentence Pointer
        /// </summary>
        public int Index
        {
            get { return _Index; }
        }

        public IList<AgentScriptSentence> ReadScript(IList<string> Scripts)
        {
            _Sentences = new List<AgentScriptSentence>();
            // Build sentence one by one
            foreach (string Sentence in Scripts)
            {
                AgentScriptSentence Script = new AgentScriptSentence(Sentence);
                _Sentences.Add(Script);
            }
            // Reset pointer
            Reset();
            return _Sentences;
        }

        public AgentScript()
        {
            _Sentences = new List<AgentScriptSentence>();
            Reset();
        }

        /// <summary>
        /// Constructor, by sentence list
        /// </summary>
        public AgentScript(IList<string> Scripts)
        {
            ReadScript(Scripts);
        }

        /// <summary>
        /// Move sentence pointer, return false if EOF
        /// </summary>
        public bool MoveNext()
        {
            if (_Index < Sentences.Count - 1)
            {
                _Index++;
                return true;
            }
            else
                return false;   // EOF
        }

        /// <summary>
        /// Return current sentence and move next
        /// </summary>
        public AgentScriptSentence Next()
        {
            AgentScriptSentence Sentence = _Sentences[_Index];
            MoveNext();
            return Sentence;
        }

        /// <summary>
        /// End of script?
        /// </summary>
        public bool EndOfScript
        {
            get { return _Index >= _Sentences.Count - 1; }
        }

        /// <summary>
        /// Reset sentence pointer
        /// </summary>
        public void Reset()
        { 
            _Index = 0;
        }


    }
}
